package net.peelmeagrape.hibernate;

import net.peelmeagrape.hibernate.xmlgen.*;

import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * Entity's natural key information.
 * <p>
 * Even though we recommend the use of surrogate keys as primary keys, you should still try
 * to identify natural keys for all entities. A natural key is a property or combination of
 * properties that is unique and non-null. If it is also immutable, even better. Map the
 * properties of the natural key using {@link net.peelmeagrape.hibernate.Property#naturalId()},
 * {@link net.peelmeagrape.hibernate.ManyToOne#naturalId()}.
 * Hibernate will generate the necessary unique key and nullability constraints, and your
 * mapping will be more self-documenting.
 * </p><p>
 * We strongly recommend that you implement {@link Object#equals(Object)} and
 * {@link Object#hashCode()} to compare the natural key properties of the entity.
 * </p><p>
 * This mapping is not intended for use with entities with natural primary keys ({@link CompositeId}).
 * </p>
 * 
 */
@Retention(RUNTIME)
@XmlElement(name="natural-id")
public @interface NaturalId
{
    /**
     * By default, natural identifier properties as assumed to be immutable (constant).
     */
    @XmlAttribute boolean mutable() default false;
}
